package com.lehezn.opensource.appkit.ControlModule;

/**
 * Created by 97629 on 2018/1/12.
 */

public class UtilOfSetting {

    public static int[] meterIntervalValueArr = new int[]{15, 30, 60, 180, 360, 540};
    public static int[] meterSumPollValueArr = new int[]{3, 5, 10, 15, 20, 40, 60};
    public static int[] powerChangeValueArr =new int[]{20, 30, 100, 300};
    public  static int[] gosWaterPollValueArr = new int[]{1, 3, 6, 9, 12, 24};


    /**
     * 范围0-300 单位是分钟
     * <string-array name="meter_interval">
     * <item>15分钟</item>
     * <item>30分钟 </item>
     * <item>1小时</item>
     * <item>3小时</item>
     * <item>6小时</item>
     * <item>9小时</item>
     * </string-array>
     */
    public static int convertMeterIntervalSpinnerPosToInteger(int pos) {
        return meterIntervalValueArr[pos];
    }

    public static int convertMeterIntervalValueToSpinnerPos(int value) {
        return findPosByValue(meterIntervalValueArr, value);
    }

    /**
     * //范围是1-60 单位是分钟
     * <string-array name="meter_sum_poll">
     * <item>3分钟</item>
     * <item>5分钟</item>
     * <item>10分钟</item>
     * <item>15分钟</item>
     * <item>20分钟</item>
     * <item>40分钟</item>
     * <item>60分钟 </item>
     * </string-array>
     *
     * @param pos
     * @return
     */
    public static int convertMeterSumPollSpinnerPosToInteger(int pos) {
        return meterSumPollValueArr[pos];
    }

    public static int convertMeterSumPollValueToSpinnerPos(int value) {
        return findPosByValue(meterSumPollValueArr, value);
    }

    /**
     * //范围20-2000 步长20
     * <string-array name="power_change_value">
     * <item>20瓦</item>
     * <item>30瓦 </item>
     * <item>100瓦</item>
     * <item>300瓦</item>
     * </string-array>
     *
     * @param pos
     * @return
     */
    public static int convertMeterPowerChangeSpinnerPosToInteger(int pos) {
        return powerChangeValueArr[pos];
    }

    public static int convertMeterPowerChangeValueToSpinnerPos(int value) {
        return findPosByValue(powerChangeValueArr, value);
    }

    /**
     * //单位是小时
     <string-array name="gos_water_poll">
     <item>1小时</item>
     <item>3小时</item>
     <item>6小时</item>
     <item>9小时</item>
     <item>12小时</item>
     <item>24小时</item>
     </string-array>
     * @param pos
     * @return
     */
    public static int convertGosWaterPollSpinnerPosToInteger(int pos) {
        return gosWaterPollValueArr[pos];
    }

    public static int convertGasWaterPollValueToSpinnerPos(int value) {
        return findPosByValue(gosWaterPollValueArr, value);
    }

    public static int findPosByValue(int[] valueArr, int value) {
        for (int i = 0; i < valueArr.length; i++) {
            if (valueArr[i] == value) {
                return i;
            }
        }
        return 0;
    }
}
